package site.yunnong.atvris.common.utils;

/**
 * @author zjh
 * @date 2021/9/9 10:10
 */
public class RedisKeyUtils {
    
    private static final String SPLIT = ":";
    
    private static final String PREFIX_USER_FANS = "fans:user";
    
    private static final String PREFIX_USER_FOLLOW = "follow:user";

    private static final String PREFIX_CLICK_TIME_LIMIT = "click-time-limit";
    
    private static final String PREFIX_VIEW_TIME_LIMIT = "view-time-limit";
    
    private static final String PREFIX_MEDIA = "media";

    public static final String exposureCountHashKey = "exposureCount";
    public static final String clickCountHashKey = "clickCount";
    public static final String viewCountHashKey = "viewCount";
    public static final String likedCountHashKey = "likedCount";
    public static final String starCountHashKey = "starCount";
    public static final String commentCountHashKey = "commentCount";
    public static final String shareCountHashKey = "shareCount";
    
    // 点击
    private static final String PREFIX_MEDIA_CLICK = "click:media-count";
    // 播放
    private static final String PREFIX_MEDIA_VIEW = "view:media";
    // 点赞
    private static final String PREFIX_MEDIA_LIKE = "like:media";
    // 计算热度
    private static final String PREFIX_MEDIA_SCORE = "score:media";
    // uuid
    private static final String PREFIX_USER = "user";
    // 访客
    private static final String PREFIX_UV = "uv";
    // 单日访客
    private static final String PREFIX_DUV = "duv";
    // 用户获赞
    private static final String PREFIX_USER_LIKE = "like:user";
    // 用户获得播放
    private static final String PREFIX_USER_VIEW = "view:user";
    
    private static final String PREFIX_MEDIA_SCORE_LOCK = "score-lock:media";

    public static String getMediaKey(Integer mediaType, Long mediaId) {
        return PREFIX_MEDIA + SPLIT + mediaType + SPLIT + mediaId;
    }

    /**
     * 锁，避免短时间重复点击计数
     * @param mediaType
     * @param mediaId
     * @param userUniqueCode
     * @return
     */
    public static String getMediaClickTimeLimitKey(Integer mediaType, Long mediaId, String userUniqueCode) {
        return PREFIX_CLICK_TIME_LIMIT + SPLIT + mediaType + SPLIT + mediaId + SPLIT + userUniqueCode;
    }

    /**
     * 锁，避免短时间内重复播放计数
     * @param mediaType
     * @param mediaId
     * @param userUniqueCode
     * @return
     */
    public static String getMediaViewTimeLimitKey(Integer mediaType, Long mediaId, String userUniqueCode) {
        return PREFIX_VIEW_TIME_LIMIT + SPLIT + mediaType + SPLIT + mediaId + SPLIT + userUniqueCode;
    }
    
    public static String getMediaScoreLockKey(Integer mediaType, Long pid) {
        return PREFIX_MEDIA_SCORE_LOCK + SPLIT + mediaType + SPLIT + pid;
    }
    
    public static String getMediaLikeSetKey(Integer mediaType, Long mediaId) {
        return PREFIX_MEDIA_LIKE + SPLIT + mediaType + SPLIT + mediaId;
    }
    
    public static String getUserKey(Long uuid) {
        return PREFIX_USER + SPLIT + uuid;
    }

    public static String getUserFansKey(Long uuid) {
        return PREFIX_USER_FANS + SPLIT + uuid;
    }

    public static String getUserFollowKey(Long uuid) {
        return PREFIX_USER_FOLLOW + SPLIT + uuid;
    }

    /**
     * set的key，
     * @return
     */
    public static String getMediaScoreKey(Integer mediaType) {
        return PREFIX_MEDIA_SCORE + SPLIT + mediaType;
    }

    public static String getRankKey(Long pid, Integer mediaType) {
        return PREFIX_MEDIA_SCORE + SPLIT + mediaType + SPLIT + pid;
    }
}
